#!/usr/bin/env node

const path = require('path');
const init = require('./init');
const { new_main } = require('./new');
const log = require('./utils/log');
const startServer = require('./web/scriptServer');

function main() {
  global.appRoot = path.join(__dirname).replace(/\\/g, '/');
  global.cwdPath = process.cwd().replace(/\\/g, '/');
  global.log = log;

  // console.log("global.cwdPath", global.cwdPath);

  // console.log(process.argv);

  if (process.argv.length < 3) {
    // TODO: 打印可用选项
    log.warn('hello yh-page\n');
    return;
  }
  const type = process.argv[2];
  // console.log('type', type);
  if (type === 'init') {
    init();
    return;
  }
  if (type === 'create' || type === 'new') {
    new_main();
    return;
  }

  if (type === 'web') {
    const INSERT_ELE = 'ROOT';
    const opts = {
      INSERT_ELE,
      WRITE_PATH: '',
      PORT: 63221,
    };

    startServer(opts);
    return;
  }

  log.warn('input the correct commands');
}

main();
